var wh = $(window).height();
$(function(){
	init();
});
function init(){
	e();
	s();
}
var part4Ani = false,part5Ani = false,part6Ani = false;
function e(){
	$(window).scroll(function () {
		// console.log($(this).scrollTop());
		// if (($(this).scrollTop()>(1400-wh)) && ($(this).scrollTop()<2500)) {
		// console.log((1500-1020)*(($(this).scrollTop()-1400+wh)/(2500-1400+wh)));
		// 	$(".part3-bg").css({
		// 		"-webkit-transform":"translateY(-"+(1500-1020)*(($(this).scrollTop()-1400+wh)/(2500-1400+wh))+"px)"
		// 	});	
		// }
		if($(this).scrollTop()>1800){
			if(!part4Ani){
				$(".part4").addClass("active");
				part4Ani = true;
			}
		}else if($(this).scrollTop()<935){
			if(part4Ani){
				$(".part4").removeClass("active");
				part4Ani = false;
			}
		}
		if($(this).scrollTop()>3300){
			if(!part5Ani){
				$(".part5").addClass("active");
				part5Ani = true;
			}
		}else if($(this).scrollTop()<2800){
			if(part5Ani){
				$(".part5").removeClass("active");
				part5Ani = false;
			}
		}

		if($(this).scrollTop()>4300){
			if(!part6Ani){
				$(".part6").addClass("active");
				part6Ani = true;
			}
		}else if($(this).scrollTop()<3500){
			if(part6Ani){
				$(".part6").removeClass("active");
				part6Ani = false;
			}
		}
	});
}

// swiper初始化
function s(){
	// 首页banner
	homeBanner = new Swiper(".homeBanner",{
		autoplay: 3000,
		pagination : '.homeBanner-pagination',
		paginationClickable :true
	});
}
$(".form-btn2").click(function(){
	var name = $(".input-name").val(),
		phone = $(".input-phone").val(),
		grade = $("select[name='grade']").val(),
		subject = $("select[name='subject']").val(),
        remark = $(".input-remark").val(),
        phone_code = $(".input-phone-code").val();
	if(!name){
		alert("姓名不能为空");
		return false;
	}
	if(!phone){
        alert("手机号码不能为空");
        return false;
	}
    if(!(/^1[34578]\d{9}$/.test(phone))){
        alert("手机号码有误");
        return false;
    }
	if(!grade){
        alert("年级不能为空");
        return false;
	}
	if(!subject){
        alert("科目不能为空");
        return false;
	}
    if(!remark){
        alert("备注不能为空");
        return false;
    }
    if(!phone_code){
        alert("验证码不能为空");
        return false;
    }
    if(phone_code&&name&&phone&&grade&&subject&&(/^1[34578]\d{9}$/.test(phone))){
        $(".form-btn").attr("disabled", true);
        $('.form-btn').text("正在提交......").css("cssText","background-color: rgb(189, 189, 189);box-shadow: 0px 0px 0px transparent;");
    }
	var post = {"name":name,"phone":phone,"phone_code":phone_code,"grade":grade,"subject":subject,"remarke_type":2,'remark':remark};
	$.ajax({
        type: "POST",dataType:"json", url: "index.php?s=mobile&c=home&m=activity", data: post,
        success: function(data) {
            if (data.status) {
                dr_tips(data.code, 3, 1);
                //$(".form-btn2").attr("disabled", true);

                $(".success-poup-box").fadeIn("slow");
                $(".success-poup-box").delay(2000).fadeOut("slow");
                //window.location.href = './index.php?s=mobile&c=home&m=sexteenclassactivity';
                setTimeout('window.location.href="./index.php?s=mobile&c=home&m=sexteenclassactivity"',2000);
                // setTimeout('window.location.href="'+data.backurl+'"', <?php echo $_GET['debug'] ? 999999: 2000;?>);
            } else {
                dr_tips(data.code);
                history.go(-1);
            }
        },
        error: function(HttpRequest, ajaxOptions, thrownError) {
            alert(HttpRequest.responseText);
        }
	});
});


$(".form-btn3").click(function(){
    var name = $(".input-name").val(),
        phone = $(".input-phone").val(),
        remark = $(".input-remark").val(),
        phone_code = $(".input-phone-code").val(),
		address = $("[name='userProvinceId']").val();
    if(!name){
        alert("姓名不能为空");
        return false;
    }
    if(!phone){
        alert("手机号码不能为空");
        return false;
    }
    if(!(/^1[34578]\d{9}$/.test(phone))){
        alert("手机号码有误");
        return false;
    }
    if(!remark){
        alert("备注不能为空");
        return false;
    }
    if(!phone_code){
        alert("验证码不能为空");
        return false;
    }
    if(phone_code&&name&&phone&&(/^1[34578]\d{9}$/.test(phone))){
        $(".form-btn").attr("disabled", true);
        $('.form-btn').text("正在提交......").css("cssText","background-color: rgb(189, 189, 189);box-shadow: 0px 0px 0px transparent;");
    }
    var post = {"name":name,"phone":phone,"phone_code":phone_code,"remarke_type":2,'remark':remark};
    $.ajax({
        type: "POST",dataType:"json", url: "index.php?s=mobile&c=home&m=wei_bo", data: post,
        success: function(data) {
            if (data.status) {
                dr_tips(data.code, 3, 1);
                //$(".form-btn2").attr("disabled", true);

                $(".success-poup-box").fadeIn("slow");
                $(".success-poup-box").delay(2000).fadeOut("slow");
                //window.location.href = './index.php?s=mobile&c=home&m=sexteenclassactivity';
                setTimeout('window.location.href="./index.php?s=mobile&c=home&m=wei_bo"',2000);
                // setTimeout('window.location.href="'+data.backurl+'"', <?php echo $_GET['debug'] ? 999999: 2000;?>);
            } else {
                dr_tips(data.code);
                history.go(-1);
            }
        },
        error: function(HttpRequest, ajaxOptions, thrownError) {
            alert(HttpRequest.responseText);
        }
    });
});



$('[name~=grade]').css('color','#9e9e9e');
$('[name~=grade]').change(function() {
    var current = $('[name~=grade]').val();
    if (current != '') {
        $('[name~=grade]').css('color','#333333');
    } else {
        $('[name~=grade]').css('color','#9e9e9e');
    }
});
$('[name~=subject]').css('color','#9e9e9e');
$('[name~=subject]').change(function() {
    var current = $('[name~=subject]').val();
    if (current != '') {
        $('[name~=subject]').css('color','#333333');
    } else {
        $('[name~=subject]').css('color','#9e9e9e');
    }
});